﻿namespace SampleApplication.ViewModels
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.ComponentModel.DataAnnotations;
    using Okazuki.MVVM.PrismSupport.ViewModels;
    using SampleApplication.Models;
    using Okazuki.MVVM.PrismSupport.Utils;
    using Microsoft.Practices.Prism.Commands;
    using Microsoft.Practices.Prism.Interactivity.InteractionRequest;

    public partial class PersonRecordViewModel : ViewModelBase
    {
        private MainViewModel Parent { get; set; }

        public Person Model { get; private set; }
        
        public string Name { get; private set; }

        public DateTime? Birthday { get; private set; }

        [AutoInitCommand]
        public DelegateCommand EditCommand { get; private set; }

        [AutoInitCommand]
        public DelegateCommand DeleteCommand { get; private set; }

        public PersonRecordViewModel(MainViewModel parent, Person model)
        {
            this.Parent = parent;
            this.Model = model;
            this.ApplyModelProperty();
        }

        public void ApplyModelProperty()
        {
            ObjectUtils.CopyTo(this.Model, this);
        }

        [CommandMethod]
        private void EditExecute()
        {
            this.Parent.EditCommand.Execute(this);
        }

        [CommandMethod]
        private void DeleteExecute()
        {
            this.Parent.DeleteCommand.Execute(this);
        }
    }
}
